package com.ruoyi.surfacewater.service.impl;

import com.ruoyi.base.mapper.PublicToolsMapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ListDataUtil;
import com.ruoyi.surfacewater.mapper.ManualComparisonOfWaterQualityMapper;
import com.ruoyi.surfacewater.service.ExcellentAndUpToStandardUtliService;
import com.ruoyi.surfacewater.service.MaunalComparisonOfWaterQualityService;
import com.ruoyi.utli.SegmentFormula;
import com.ruoyi.utli.mapper.SegmentUtliMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class MaunalComparisonOfWaterQualityServiceImpl implements MaunalComparisonOfWaterQualityService {

    @Autowired
    private PublicToolsMapper publicToolsMapper;
    @Autowired
    private SegmentFormula segmentFormula;
    @Autowired
    private ManualComparisonOfWaterQualityMapper manualComparisonOfWaterQualityMapper;

    @Autowired
    private ExcellentAndUpToStandardUtliService excellentAndUpToStandardUtliService;

    @Override
    public List<Map<String, Object>> countySectionWaterQualityIndex(Map<String, Object> map) {
        //存放返回数据
        List<Map<String, Object>> mapdatalist = new ArrayList<>();
        Object dataTime = map.get("dataTime");//时间
        Object whetherYOY = map.get("whetherYOY");//是否展示同比
        Object bussinessCategoryCode = map.get("bussinessCategoryCode");//数据类型
        Object accumulate = map.get("accumulate");//是否累计
        List<String> assessTypeCodes = (List<String>) map.get("assessTypeCodes");//考核编码 0国考 1省考 2市考

        //List<String> segmentIds = (List<String>) map.get("SegmentIDs");//断面id
        List<String> segmentIds = new ArrayList<>();//断面id
        List<String> countyCodes = (List<String>) map.get("countyCodes");//区划编码
        if (countyCodes != null && countyCodes.size() > 0) {
            //如果默认断面id为空 考核类型为空就默认获取全部的断面id
            Map<String, Object> WqBasSegmentNameAllmap = new HashMap<>();
            WqBasSegmentNameAllmap.put("segmentType", "IsManual");
            WqBasSegmentNameAllmap.put("Segmenttype", "RiverSegment");
            WqBasSegmentNameAllmap.put("segmentTypes", "IsManualIsDrink");
            // WqBasSegmentNameAllmap.put("CountyCodes", countyCodes);
            WqBasSegmentNameAllmap.put("AssessTownCode", countyCodes);
            WqBasSegmentNameAllmap.put("dataTime", dataTime);
            if (assessTypeCodes != null && assessTypeCodes.size() > 0) {
                WqBasSegmentNameAllmap.put("assessTypeCode", assessTypeCodes);
                WqBasSegmentNameAllmap.put("Type", "CountyCode");
            }
            List<Map> list = publicToolsMapper.WqBasSegmentNameAlldataTime(WqBasSegmentNameAllmap);
            //List<Map> list = SegmentUtliMapper.WqBasSegmentNameAll(WqBasSegmentNameAllmap);
            if (list != null && list.size() > 0) {
                for (Map<String, Object> data : list) {
                    Object id = data.get("ID");//断面id
                    segmentIds.add(String.valueOf(id));
                }
            }
        }

        Map<String, Object> SegmentIdsksjsdatatimemap = new HashMap<>();
        SegmentIdsksjsdatatimemap.put("dataTime", dataTime);
        SegmentIdsksjsdatatimemap.put("segmentIds", segmentIds);
        SegmentIdsksjsdatatimemap.put("assessTypeCodes", assessTypeCodes);
        Map<String, Object> stringObjectMap = this.SegmentIdsksjsdatatime(SegmentIdsksjsdatatimemap);
        String beginTime = (String) stringObjectMap.get("beginTime");//当期开始时间 根据传入年份拼接一月份开始
        List<Map<String, Object>> ItemIsRiverEvalute = (List<Map<String, Object>>) stringObjectMap.get("ItemIsRiverEvalute");//是否展示因子数据
        List<String> monthall = (List<String>) stringObjectMap.get("monthall");//当期月份
        String tbjsData = (String) stringObjectMap.get("tbjsData");//同比结束时间
        String tbksData = (String) stringObjectMap.get("tbksData");//同比开始时间
        List<String> tbmonthall = (List<String>) stringObjectMap.get("tbmonthall");//同比月份
        // 1.查询所属区县的对应类型 湖库 河流 查询出对应数量和id
        List<String> SegmentIds = (List<String>) stringObjectMap.get("SegmentIds");//断面id
        List<String> hkSegmentIdsone = (List<String>) stringObjectMap.get("hkSegmentIdsone");//断面id
        List<String> hlSegmentIdsone = (List<String>) stringObjectMap.get("hlSegmentIdsone");//断面id
        List<Map<String, Object>> hkSegmentIds = (List<Map<String, Object>>) stringObjectMap.get("hkSegmentIds");//湖库断面id
        List<Map<String, Object>> hlSegmentIds = (List<Map<String, Object>>) stringObjectMap.get("hlSegmentIds");//河流断面id
        //List<String> CityCodes = (List<String>) stringObjectMap.get("CityCodes");//区划
        List<String> CityCodes = countyCodes;//区划
        List<Map<String, Object>> segmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("segmentCountysl");//当期时间的不通区划断面类型的有数据数量统计
        List<Map<String, Object>> tbsegmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountysl");//同比时间的不通区划断面类型的有数据数量统计
        List<Map<String, Object>> segmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("segmentCountyslall");//同比时间的不通区划断面类型的有数据数量统计
        List<Map<String, Object>> tbsegmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountyslall");//同比时间的不通区划断面类型的有数据数量统计

        //获取总数计算权重
        Map<String, Object> countySectionWaterQualityIndexmap = new HashMap<>();
        if (accumulate != null && !"".equals(accumulate) && "0".equals(accumulate)) {
            //得到对应的数据id进行查询对应均值数据
            //湖库对应断面均值（以区划进行分组）
            List<Map<String, Object>> hkmaps = new ArrayList<>();
            List<Map<String, Object>> hkdataall = new ArrayList<>();
            List<Map<String, Object>> ljhkmaps = new ArrayList<>();
            List<Map<String, Object>> allljhkmaps = new ArrayList<>();
            if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
                Map<String, Object> hkmanualIndexMonthlyData = new HashMap<>();
                hkmanualIndexMonthlyData.put("SegmentIds", hkSegmentIdsone);
                hkmanualIndexMonthlyData.put("beginTime", beginTime);
                hkmanualIndexMonthlyData.put("endTime", dataTime);
                hkmanualIndexMonthlyData.put("AssessTownCode", CityCodes);
                hkmanualIndexMonthlyData.put("bussinessCategoryCode", bussinessCategoryCode);
                hkmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
                hkmanualIndexMonthlyData.put("SampleDate", "moon");
                hkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
                hkmanualIndexMonthlyData.put("Segmenttype", "Segment");
                hkdataall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
                hkmanualIndexMonthlyData.put("Segmenttype", "Segment");
                hkmanualIndexMonthlyData.put("SampleDate", "");
                hkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                ljhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
                hkmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
                allljhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);

            }
            //河流对应断面均值（以区划进行分组）
            List<Map<String, Object>> hlmaps = new ArrayList<>();
            List<Map<String, Object>> hldataall = new ArrayList<>();
            List<Map<String, Object>> ljhlmaps = new ArrayList<>();
            List<Map<String, Object>> allljhlmaps = new ArrayList<>();
            if (hlSegmentIdsone != null && hlSegmentIdsone.size() > 0) {
                Map<String, Object> hlmanualIndexMonthlyData = new HashMap<>();
                hlmanualIndexMonthlyData.put("SegmentIds", hlSegmentIdsone);
                hlmanualIndexMonthlyData.put("beginTime", beginTime);
                hlmanualIndexMonthlyData.put("endTime", dataTime);
                hlmanualIndexMonthlyData.put("AssessTownCode", CityCodes);
                hlmanualIndexMonthlyData.put("bussinessCategoryCode", bussinessCategoryCode);
                hlmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
                hlmanualIndexMonthlyData.put("SampleDate", "moon");
                hlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);
                hlmanualIndexMonthlyData.put("Segmenttype", "Segment");
                hldataall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);
                hlmanualIndexMonthlyData.put("Segmenttype", "Segment");
                hlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                hlmanualIndexMonthlyData.put("SampleDate", "");
                ljhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);
                hlmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
                allljhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);

            }

            //同比数据
            List<Map<String, Object>> tbhkmaps = new ArrayList<>();
            List<Map<String, Object>> tbhkmapsall = new ArrayList<>();
            List<Map<String, Object>> allljtbhkmaps = new ArrayList<>();
            List<Map<String, Object>> tbhlmaps = new ArrayList<>();
            List<Map<String, Object>> tbhlmapsall = new ArrayList<>();
            List<Map<String, Object>> ljtbhkmaps = new ArrayList<>();
            List<Map<String, Object>> ljtbhlmaps = new ArrayList<>();
            List<Map<String, Object>> allljtbhlmaps = new ArrayList<>();
            //湖库对应断面均值（以区划进行分组）
            if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
                Map<String, Object> tbhkmanualIndexMonthlyData = new HashMap<>();
                tbhkmanualIndexMonthlyData.put("SegmentIds", hkSegmentIdsone);
                tbhkmanualIndexMonthlyData.put("beginTime", tbksData);
                tbhkmanualIndexMonthlyData.put("endTime", tbjsData);
                tbhkmanualIndexMonthlyData.put("AssessTownCode", CityCodes);
                tbhkmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
                tbhkmanualIndexMonthlyData.put("SampleDate", "moon");
                tbhkmanualIndexMonthlyData.put("bussinessCategoryCode", bussinessCategoryCode);
                tbhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);
                tbhkmanualIndexMonthlyData.put("Segmenttype", "Segment");
                tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                tbhkmapsall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);
                tbhkmanualIndexMonthlyData.put("Segmenttype", "Segment");
                tbhkmanualIndexMonthlyData.put("SampleDate", "");
                tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                ljtbhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);
                tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
                allljtbhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);

            }
            //河流对应断面均值（以区划进行分组）
            if (hlSegmentIdsone != null && hlSegmentIdsone.size() > 0) {
                Map<String, Object> tbhlmanualIndexMonthlyData = new HashMap<>();
                tbhlmanualIndexMonthlyData.put("SegmentIds", hlSegmentIdsone);
                tbhlmanualIndexMonthlyData.put("beginTime", tbksData);
                tbhlmanualIndexMonthlyData.put("endTime", tbjsData);
                tbhlmanualIndexMonthlyData.put("AssessTownCode", CityCodes);
                tbhlmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
                tbhlmanualIndexMonthlyData.put("SampleDate", "moon");
                tbhlmanualIndexMonthlyData.put("bussinessCategoryCode", bussinessCategoryCode);
                tbhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);
                tbhlmanualIndexMonthlyData.put("Segmenttype", "Segment");
                //tbhlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                tbhlmapsall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);
                tbhlmanualIndexMonthlyData.put("Segmenttype", "Segment");
                tbhlmanualIndexMonthlyData.put("SampleDate", "");
                tbhlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
                ljtbhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);
                tbhlmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
                allljtbhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);

            }
            countySectionWaterQualityIndexmap.put("allljhkmaps", allljhkmaps);
            countySectionWaterQualityIndexmap.put("allljhlmaps", allljhlmaps);
            countySectionWaterQualityIndexmap.put("allljtbhkmaps", allljtbhkmaps);
            countySectionWaterQualityIndexmap.put("allljtbhlmaps", allljtbhlmaps);
            countySectionWaterQualityIndexmap.put("hkdata", hkmaps);
            countySectionWaterQualityIndexmap.put("hkdataall", hkdataall);
            countySectionWaterQualityIndexmap.put("hldataall", hldataall);
            countySectionWaterQualityIndexmap.put("tbhkmapsall", tbhkmapsall);
            countySectionWaterQualityIndexmap.put("tbhlmapsall", tbhlmapsall);
            countySectionWaterQualityIndexmap.put("hldata", hlmaps);
            countySectionWaterQualityIndexmap.put("tbhkmaps", tbhkmaps);
            countySectionWaterQualityIndexmap.put("tbhlmaps", tbhlmaps);
            countySectionWaterQualityIndexmap.put("ljhkdata", ljhkmaps);
            countySectionWaterQualityIndexmap.put("ljhldata", ljhlmaps);
            countySectionWaterQualityIndexmap.put("ljtbhkmaps", ljtbhkmaps);
            countySectionWaterQualityIndexmap.put("ljtbhlmaps", ljtbhlmaps);
        }
        //}


        countySectionWaterQualityIndexmap.put("ItemIsRiverEvalute", ItemIsRiverEvalute);

        countySectionWaterQualityIndexmap.put("CityCodes", CityCodes);

        countySectionWaterQualityIndexmap.put("monthall", monthall);

        countySectionWaterQualityIndexmap.put("hkSegmentIdsone", hkSegmentIdsone);
        countySectionWaterQualityIndexmap.put("hlSegmentIdsone", hlSegmentIdsone);
        countySectionWaterQualityIndexmap.put("tbsegmentCountyslall", tbsegmentCountyslall);
        countySectionWaterQualityIndexmap.put("segmentCountyslall", segmentCountyslall);

        countySectionWaterQualityIndexmap.put("whetherYOY", whetherYOY);
        countySectionWaterQualityIndexmap.put("accumulate", accumulate);
        countySectionWaterQualityIndexmap.put("tbmonthall", tbmonthall);
        countySectionWaterQualityIndexmap.put("type", "yar");
        countySectionWaterQualityIndexmap.put("segmentCountysl", segmentCountysl);
        countySectionWaterQualityIndexmap.put("tbsegmentCountysl", tbsegmentCountysl);
        countySectionWaterQualityIndexmap.put("assessTypeCodes", assessTypeCodes);
        countySectionWaterQualityIndexmap.put("dataTime", dataTime);
        Map<String, Object> allsegmentdatalist = new HashMap<>();
        //判断是否进行累计计算
        List<Map<String, Object>> accumulatelist = new ArrayList<>();
        if (accumulate != null && !"".equals(accumulate) && "0".equals(accumulate)) {
            Map<String, Object> countySectionWaterQualityIndexlist = excellentAndUpToStandardUtliService.countySectionWaterQualityIndex(countySectionWaterQualityIndexmap);
            if (countySectionWaterQualityIndexlist != null && countySectionWaterQualityIndexlist.size() > 0) {
                Object segmentdata = countySectionWaterQualityIndexlist.get("segmentdata");
                Object allsegmentdata = countySectionWaterQualityIndexlist.get("allsegmentdata");
                if (segmentdata != null && !"".equals(segmentdata)) {
                    List<Map<String, Object>> maplist = (List<Map<String, Object>>) segmentdata;
                    if (maplist != null && maplist.size() > 0) {
                        for (Map<String, Object> mapdata : maplist) {
                            Object countyCode = mapdata.get("countyCode");
                            Object county = mapdata.get("county");
                            accumulatelist.add(mapdata);
                        }
                    }
                }
                if (allsegmentdata != null && !"".equals(allsegmentdata)) {
                    allsegmentdatalist = (Map<String, Object>) allsegmentdata;
                }
            }

        }

        //累计计算
        if (accumulate != null && !"".equals(accumulate) && "1".equals(accumulate)) {
            Map<String, Object> ljcountySectionWaterQualityIndexlist = excellentAndUpToStandardUtliService.ljcountySectionWaterQualityIndex(countySectionWaterQualityIndexmap);
            if (ljcountySectionWaterQualityIndexlist != null && ljcountySectionWaterQualityIndexlist.size() > 0) {
                Object segmentdata = ljcountySectionWaterQualityIndexlist.get("segmentdata");
                Object allsegmentdata = ljcountySectionWaterQualityIndexlist.get("allsegmentdata");
                if (segmentdata != null && !"".equals(segmentdata)) {
                    List<Map<String, Object>> maplist = (List<Map<String, Object>>) segmentdata;
                    if (maplist != null && maplist.size() > 0) {
                        for (Map<String, Object> mapdata : maplist) {
                            Object countyCode = mapdata.get("countyCode");
                            Object county = mapdata.get("county");
                            accumulatelist.add(mapdata);
                        }
                    }
                }
                if (allsegmentdata != null && !"".equals(allsegmentdata)) {
                    allsegmentdatalist = (Map<String, Object>) allsegmentdata;
                }
            }

        }
        List<Map<String, Object>> listdatavalue = new ArrayList<>();
        //计算排名和变化率排名
        List<Map<String, Object>> bhlwaterQualityIndex = ListDataUtil.doubleascendingOrder(accumulatelist, "change");
        if (bhlwaterQualityIndex != null && bhlwaterQualityIndex.size() > 0) {
            int i = 1;
            for (Map<String, Object> data : bhlwaterQualityIndex) {
                Object change = data.get("change");
                if (change != null && !"-".equals(change)) {
                    data.put("changeranking", i++);
                }
                listdatavalue.add(data);
            }
        }
        List<Map<String, Object>> pmwaterQualityIndex = ListDataUtil.doubleascendingOrder(listdatavalue, "waterQualityIndex");
        if (pmwaterQualityIndex != null && pmwaterQualityIndex.size() > 0) {
            int k = 1;
            for (Map<String, Object> data : pmwaterQualityIndex) {
                Object change = data.get("waterQualityIndex");
                if (change != null && !"-".equals(change)) {
                    data.put("waterQualityIndexranking", k++);
                }
                mapdatalist.add(data);
            }
        }

        if (allsegmentdatalist != null && allsegmentdatalist.size() > 0) {
            mapdatalist.add(allsegmentdatalist);
        }
        return mapdatalist;
    }

    /**
     * 返回对应的断面id/开始结束时间
     * dataTime, 查询时间
     * segmentId, 断面id 多个以逗号隔开
     * assessTypeCode, 考核类型 多个以逗号隔开
     **/
    public Map<String, Object> SegmentIdsksjsdatatime(Map<String, Object> map) {
        //存放返回数据
        Map<String, Object> mapdatalist = new HashMap<>();
        Object dataTime = map.get("dataTime");//时间
        List<String> assessTypeCodes = (List<String>) map.get("assessTypeCodes");//考核编码 0国考 1省考 2市考
        List<String> segmentIds = (List<String>) map.get("segmentIds");//断面id
        //先获取传入时间的年份 直接从一月开始为开始时间
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(dfs.parse(String.valueOf(dataTime)));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int year = calendar.get(Calendar.YEAR);
        String beginTime = year + "-01";
        //需要添加同比数据
        String tbksData = null;
        String tbjsData = null;
        //调用工具类获取同比时间
        Map<String, Object> stringObjectMap = DateUtils.OnTheSameMonthRatio(beginTime, String.valueOf(dataTime), "yyyy-mm");
        if (stringObjectMap != null && stringObjectMap.size() > 0) {
            tbksData = (String) stringObjectMap.get("tbksData");
            tbjsData = (String) stringObjectMap.get("tbjsData");
        }
        //查询是否参与计算的因子
        Map<String, Object> wqBasItemIDIsRiverEvalutemap = new HashMap<>();
        wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "1");
        List<Map<String, Object>> ItemIsRiverEvalute = publicToolsMapper.wqBasItemIDIsRiverEvalute(wqBasItemIDIsRiverEvalutemap);
        //筛选需要的断面id
        List<String> SegmentIds = new ArrayList<>();
        List<String> hkSegmentIdsone = new ArrayList<>();
        List<String> tbhkSegmentIdsone = new ArrayList<>();
        List<String> hlSegmentIdsone = new ArrayList<>();
        List<String> tbhlSegmentIdsone = new ArrayList<>();
        List<String> CityCodes = new ArrayList<>();
        List<String> RiverIDs = new ArrayList<>();
        if (segmentIds != null && segmentIds.size() > 0 && assessTypeCodes != null && assessTypeCodes.size() > 0) {
            Map<String, Object> AssessTypeCodesegmentmap = new HashMap<>();
            AssessTypeCodesegmentmap.put("segmentType", "IsManual");
            AssessTypeCodesegmentmap.put("segmentTypes", "IsManualIsDrink");
            AssessTypeCodesegmentmap.put("Segmenttype", "RiverSegment");
            AssessTypeCodesegmentmap.put("segmentIds", segmentIds);//传入断面id不为空传入进行查询
            //判断考核类型不为空就传入
            if (assessTypeCodes != null && assessTypeCodes.size() > 0) {
                AssessTypeCodesegmentmap.put("Type", "CountyCode");
                AssessTypeCodesegmentmap.put("AssessTypeCodes", assessTypeCodes);
            }
            List<Map<String, Object>> maps = publicToolsMapper.AssessTypeCodesegments(AssessTypeCodesegmentmap);
            AssessTypeCodesegmentmap.put("dataTime", tbjsData);
            List<Map<String, Object>> tbmaps = publicToolsMapper.tbAssessTypeCodesegments(AssessTypeCodesegmentmap);
            if (maps != null && maps.size() > 0) {
                for (Map<String, Object> data : maps) {
                    Object id = data.get("SegmentID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("RiverID");//河流id
                    Object CountyCode = data.get("AssessTownCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        boolean RiverIDcontains = true;
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }
                    }
                }
            }

            if (tbmaps != null && tbmaps.size() > 0) {
                for (Map<String, Object> data : tbmaps) {
                    Object id = data.get("SegmentID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("RiverID");//河流id
                    //Object CountyCode = data.get("CountyCode");//区划编码
                    Object CountyCode = data.get("AssessTownCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        boolean RiverIDcontains = true;
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }
                    }
                }
            }
        } else {
            //如果默认断面id为空 考核类型为空就默认获取全部的断面id
            Map<String, Object> WqBasSegmentNameAllmap = new HashMap<>();
            WqBasSegmentNameAllmap.put("segmentType", "IsManual");
            WqBasSegmentNameAllmap.put("segmentTypes", "IsManualIsDrink");
            WqBasSegmentNameAllmap.put("Segmenttype", "RiverSegment");
            WqBasSegmentNameAllmap.put("segmentIds", segmentIds);
            List<Map> list = publicToolsMapper.WqBasSegmentNameAll(WqBasSegmentNameAllmap);
            if (list != null && list.size() > 0) {
                for (Map data : list) {
                    Object id = data.get("ID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("ThirdRiverSystemId");//河流id
                    Object CountyCode = data.get("CountyCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        // boolean hkcontains = hkSegmentIds.contains(id);
                        // boolean hlcontains = hlSegmentIds.contains(id);
                        boolean RiverIDcontains = true;
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }
                    }
                }
            }
        }
        //获取传入时间所有月份
        List<String> monthall = DateUtils.getMonthall(beginTime, String.valueOf(dataTime));


        // SegmentIds  beginTime  dataTime
        Map<String, Object> segmentCountyslmap = new HashMap<>();
        segmentCountyslmap.put("SegmentIds", SegmentIds);
        segmentCountyslmap.put("beginTime", beginTime);
        segmentCountyslmap.put("endTime", dataTime);
        List<Map<String, Object>> maps = publicToolsMapper.segmentCountysl(segmentCountyslmap);
        // tbksData  tbjsData
        Map<String, Object> tbsegmentCountyslmap = new HashMap<>();
        tbsegmentCountyslmap.put("SegmentIds", SegmentIds);
        tbsegmentCountyslmap.put("beginTime", tbksData);
        tbsegmentCountyslmap.put("endTime", tbjsData);
        List<Map<String, Object>> tbmaps = publicToolsMapper.segmentCountysl(tbsegmentCountyslmap);


        Map<String, Object> allsegmentCountyslmap = new HashMap<>();
        allsegmentCountyslmap.put("SegmentIds", SegmentIds);
        allsegmentCountyslmap.put("beginTime", beginTime);
        allsegmentCountyslmap.put("endTime", dataTime);
        List<Map<String, Object>> allmaps = publicToolsMapper.segmentCountyslall(allsegmentCountyslmap);
        // tbksData  tbjsData
        Map<String, Object> alltbsegmentCountyslmap = new HashMap<>();
        alltbsegmentCountyslmap.put("SegmentIds", SegmentIds);
        alltbsegmentCountyslmap.put("beginTime", tbksData);
        alltbsegmentCountyslmap.put("endTime", tbjsData);
        List<Map<String, Object>> alltbmaps = publicToolsMapper.segmentCountyslall(alltbsegmentCountyslmap);
        List<String> tbmonthall = DateUtils.getMonthall(tbksData, tbjsData);
        mapdatalist.put("segmentCountysl", maps);
        mapdatalist.put("segmentCountyslall", allmaps);
        mapdatalist.put("tbsegmentCountyslall", alltbmaps);
        mapdatalist.put("tbsegmentCountysl", tbmaps);
        mapdatalist.put("beginTime", beginTime);
        mapdatalist.put("ItemIsRiverEvalute", ItemIsRiverEvalute);
        mapdatalist.put("SegmentIds", SegmentIds);
        mapdatalist.put("RiverIDs", RiverIDs);
        mapdatalist.put("monthall", monthall);
        mapdatalist.put("tbjsData", tbjsData);
        mapdatalist.put("tbksData", tbksData);
        mapdatalist.put("tbmonthall", tbmonthall);
        mapdatalist.put("hkSegmentIdsone", hkSegmentIdsone);
        mapdatalist.put("hlSegmentIdsone", hlSegmentIdsone);
        mapdatalist.put("CityCodes", CityCodes);

        return mapdatalist;
    }
}
